package leetcode.code1887;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int reductionOperations(int[] nums) {
		int[] hash = new int[50001];
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < nums.length; i++) {
			hash[nums[i]]++;
			min = Math.min(min, nums[i]);
		}
		int ans = 0, sum = 0;
		for (int i = hash.length - 1; i >= 0; i--) {
			if (hash[i] != 0 && i != min) {
				sum += hash[i];
				ans += sum;
			}
		}
		return ans;
	}

	@Override
	public void debug4() {
		H.compare(3, this.reductionOperations(H.str2array3("[5,1,3]")));
		H.compare(0, this.reductionOperations(H.str2array3("[1,1,1]")));
		H.compare(4, this.reductionOperations(H.str2array3("[1,1,2,2,3]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
